import numpy as np
import matplotlib.pyplot as plt
import pdb
import datetime as dt
from pandas import *
from scipy import stats
from sklearn import linear_model
from sklearn.model_selection import cross_val_predict
import matplotlib.dates as md
data = read_csv('datasheet.csv')


time = data['Date/Time']
x = range(len(time))
y1 = data['CPU Usage %']
y2 = data['Temperature C']
fig, ax =plt.subplots()
ax.plot(x,y1,'r',label='CPU Usage %')
ax.plot(x,y2,'b',label='Temperature C')
plt.legend()
ax.set_xlabel('Date/Time')
labels = ['10:37','12:50','14:22']
plt.gca().set_xticklabels(labels)
plt.title('data 2018-04-28')
plt.figure()

y1=data['CPU Usage %']
plt.hist(y1,bins=[0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80],align='left',rwidth=0.5)
plt.title('Histogram of CPU Usage %')
plt.xlabel('CPU Usage %')
plt.figure()

y2=data['Temperature C']
plt.hist(y2,bins=[40,41.5,42,44.5,46,47.5,49,50.5,52,53.5,55,56.5,58,59.5,61,62.5,64,65.5,67,68.5,70],align='left',rwidth=0.5,color='r')
plt.title('Histogram of Temperature C')
plt.xlabel('Temperature C')
plt.figure()

y1=data['CPU Usage %']
plt.boxplot(y1,0,'rs',0)
plt.title('data 2018-04-28')
plt.xlabel('CPU Usage %')
plt.figure()

y2=data['Temperature C']
plt.boxplot(y2)
plt.title('data 2018-04-28')
plt.xlabel('Temperature C')
plt.figure()

y1=data['CPU Usage %']
y2=data['Temperature C']
slope, intercept, r_value, p_value, std_err = stats.linregress(y1,y2)
plt.xlabel('CPU Usage %')
plt.ylabel('Temperature C')
plt.title('data 2018-04-28')
plt.plot(y1,y2,'ro')
plt.plot(y1,intercept+slope*y1,'b')
plt.figure()


y1= data[['CPU Usage %']]
y2=data[['Temperature C']]
lr = linear_model.LinearRegression()
predicted = cross_val_predict(lr,y1,y2,cv=10)
fig,ax = plt.subplots()
ax.scatter(y2,predicted)
ax.plot([y2.min(),y2.max()],[y2.min(),y2.max()],'k-',lw=1)
plt.xlabel('Temperature C')
plt.title('data 2018-04-28')
plt.show()

